<template>
    <div>
        <h1>显示</h1>
        姓名 <input type="text" v-model="info.names">
        面积 <input type="text" v-model="info.min">-<input type="text" v-model="info.max">
        <input type="button" value="查询" @click="getlist">
        <table class="table table-bordered">
            <tbody>
                <tr>
                    <input type='checkbox' v-model="checked" @click="checkeAlls">
                    <td>房型名称</td>
                    <td>发布状态</td>
                    <td>上架状态</td>
                    <td>图片</td>
                    <td>创建时间</td>
                    <td>面积</td>
                    <td>操作</td>
                </tr>
                <tr v-for="itme in data.list":key="itme.Id">
                    <input type='checkbox' v-model="checkeds" :value="itme.Id" @change="checkeAll">
                    <td>{{ itme.Name }}</td>
                    <td>{{ itme.FXZT ?"发布":"不发布"}}</td>
                    <td>{{ itme.SJZT?"上架":"不上架" }}</td>
                    <td><img :src="itme.Img" width="100" height="100"></td>
                    <td>{{moment(itme.CountTime).format('YYYY-MM-DD hh:mm:ss')  }}</td>
                    <td>{{ itme.Mianji }}</td>
                    <td> <input type="button" value="删除" @click="del(itme.Id)">
                        <input type="button" value="修改" @click="xg(itme.Id)">
                    </td>
                </tr>
            </tbody>
        </table>
        <span>共<b>{{ data.totalcount }}条</b></span>
        <span>每页<b>{{ info.pagesize }}条</b></span>
        <span>共<b>{{ info.pageindex }} /{{ data.totalpage }}页</b></span>
        <input type="button" value="首页" @click="gopage(1)">
        <input type="button" value="上一页" @click="gopage(info.pageindex-1)">
        <span v-for="item in data.totalpage" @click="gopage(item)">
            {{ item }}
        </span>
        <input type="button" value="下一页" @click="gopage(info.pageindex+1)">
        <input type="button" value="尾页" @click="gopage(data.totalpage)">
    </div>
</template>

<script setup lang="ts">
import{ref, reactive,onMounted} from 'vue'
import axios from 'axios';
import { useRouter,useRoute } from 'vue-router';
import moment from 'moment';
const router=useRouter();
const route=useRoute();
let info:any=reactive({
names:'',
min:'',
max:'',
pageindex:1,
pagesize:2
})
let data:any=reactive({
    list:[],
    totalcount:0,
    totalpage:0,
})
onMounted(()=>{
    getlist();
})
let checked:any=ref(false);
let checkeds:any=ref([]);
const checkeAlls=()=>{
    checked.value=!checked.value;
    if(checked.value==true)
{
    checkeds.value=data.list.map((itme:any)=>{
        return itme.Id;
    })
   
}
else
    {
        checkeds.value=[]
        
    }
    console.log(checkeds.value);
    
}
const checkeAll=()=>{

}
//--------------------------------显示----------------------------
const getlist=()=>{
    axios({
        url:'/api/FX/GetAll',
        method:'get',
        params:info
    })
    .then((res)=>{
        console.log(res);
        Object.assign(data,res.data);
    })
    .catch((err)=>{
        console.log(err);
        
    })
}
//--------------------------------分页----------------------------
const show=()=>{
    info.pageindex=1,
    getlist()
}
const gopage=(num:any)=>{
    if(num<1)
    {
        info.pageindex=1;
        return;
    }
    if(info.pageindex>data.totalpage)
    {
        info.pageindex=data.totalpage;
        return;
    }
    info.pageindex=num
    getlist();

}
//--------------------------------删除----------------------------
const del=(id:any)=>{
    axios({
        url:'/api/FX/del',
        method:'delete',
        params:{
            id:id
        }
    })
    .then((res)=>{
        console.log(res);
        if(res.data>0)
    {
        alert('删除成功');
        getlist();
        return;
    }
    else
    {
        alert('删除失败');
        return;
    }
    
    })
    .catch((err)=>{
        console.log(err);
        
    })
}
//--------------------------------修改----------------------------
const xg=(id:any)=>{
    router.push({
        path:'/xg',
        query:{id:id}
    })
}
</script>

<style scoped>

</style>